<include file="header" />
<body class="bg-white">
<div class="wraper">
    <div class="header">
		<img src="/assets/schoolirs/images/header.png"/>
		<div class="reg_info">
			<img class="reg_photo" src="{BEESCRM:$Wechat.avatar}"/>
			<p>{BEESCRM:$Wechat.nickname}</p>
		</div>
    </div>
	<div class="login">
		<div class="form-box">
			<div class="form-list tb-mode">
				<p class="tb-cell mark"><span class="iconfont icon-gongsi"></span></p>
				<p class="tb-cell">
					<select name="sel-department" id="departmentId">
						<option value="0">请选择一级单位</option>
						<volist name="Department" id="vo">
							<option value="{BEESCRM:$vo.department_id}">{BEESCRM:$vo.department_name}</option>
						</volist>
					</select>
				</p>
				<p class="iconfont icon-you"></p>
			</div>
			<div class="form-list tb-mode">
				<p class="tb-cell mark"><span class="iconfont icon-gongsi"></span></p>
				<p class="tb-cell">
					<select name="sel-department" id="department">
						<option value="0">请选择二级单位</option>
					</select>
				</p>
				<p class="iconfont icon-you"></p>
			</div>
			<div class="form-list tb-mode">
				<p class="tb-cell mark"><span class="iconfont icon-zhanghaozhongxin"></span></p>
				<p class="tb-cell"><input name="user_name" id="user_name" value="{BEESCRM:$name}" placeholder="请输入您的姓名"/></p>
			</div>
			<div class="form-list tb-mode">
				<p class="tb-cell mark"><span class="iconfont icon-shouji1"></span></p>
				<p class="tb-cell"><input name="user_mobile" id="user_mobile" value="{BEESCRM:$mobile}" placeholder="请输入您的手机号码"/></p>
			</div>
			<div class="form-list tb-mode">
				<p class="tb-cell mark"><span class="iconfont icon-yanzhengma"></span></p>
				<p class="tb-cell"><input name="code" id="code" placeholder="请输入验证码"/></p>
				<p class="tb-cell"><a href="javascript:void(0)" class="btn send">获取验证码</a></p>
			</div>
			<a href="javascript:void(0)" class="btn doReg">注册</a>
		</div>
	</div>
</div>
<input type="hidden" value="{BEESCRM:$vo.irs_id}" id="irs_id">
<input type="hidden" value="{BEESCRM:$flag}" id="flag">
<include file="commonJS" />
<script>
	$("#departmentId").change(function () {
		var id = $("#departmentId").val();
		var department = getParams(id);
		var options = [];
		if(Number(department) == 0){
			var option = '<option value="0">请选择二级单位</option>';
			options.push(option);
		}else{
			var option = '<option value="0">请选择二级单位</option>';
			options.push(option);
			$.each(department, function (index, node) {
				var option = '<option value="' + node.department_id+'">' + node.department_name + '</option>';
				options.push(option);
			});
		}
		$("#department").html(options.join(''));
	});

	function getParams(id){
		id = id ? id : 0;
		var result = null;
		$.ajax({
			url: "/Zyyirs/Irs/ajaxGetDepartment",
			type: "post",
			dataType: 'json',
			async: false,
			data: {
				id: id,
			},
			success: function (data) {
				if (data.status == 'S') {
					result = data.res;
				}
			}
		});
		return result;
	}

	$(".doReg").on('click',function(){
		var departmentId = $("#department").val();
		var user_name    = $("#user_name").val();
		var user_mobile  = $("#user_mobile").val();
		var code 		 = $("#code").val();
		var irs_id       = $("#irs_id").val();
		var flag		 = $("#flag").val();
		if(departmentId == 0){
			fm.alert('请选择单位');
			return false;
		}
		if(user_name == ''){
			fm.alert('请填写姓名');
			return false;
		}if(user_mobile == ''){
			fm.alert('请填写手机号');
			return false;
		}
		var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
		if(!myreg.test(user_mobile))
		{
			fm.alert('请输入有效的手机号码！');
			return false;
		}
		if(code == ''){
			fm.alert('请输入验证码！');
			return false;
		}
		var info = {};
		var json = {};
		info.departmentId = departmentId;
		info.user_name = user_name;
		info.user_mobile = user_mobile;
		info.code = code;
		info.flag = flag;
		$.ajax({
			'url': "/Zyyirs/irs/doReg?irs_id="+irs_id,
			'data': info,
			'dataType':'json',
			'type': 'POST',
			'async': false,
			success: function(data) {
				if (data.status == 'S') {
					setTimeout("reload('"+data.url+"')", 2000);
					fm.alert(data.message);

				}else{
					fm.alert(data.message);
					return false;
				}
			}
		});
	});

	verifyTag = true;
	$(".send").on('click',function(){
		if(verifyTag){
			var user_mobile  = $("#user_mobile").val();
			var irs_id       = $("#irs_id").val();
			if(user_mobile == ''){
				fm.alert('请填写手机号');
				return false;
			}
			var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
			if(!myreg.test(user_mobile))
			{
				fm.alert('请输入有效的手机号码！');
				return false;
			}
			timeCount();
			var info = {};
			var json = {};
			info.user_mobile = user_mobile;
			$.ajax({
				'url': "/Zyyirs/irs/sendText?irs_id="+irs_id,
				'data': info,
				'dataType':'json',
				'type': 'POST',
				'async': false,
				success: function(data) {
					if (data.status == 'S') {
						fm.alert(data.message);
					}else{
						fm.alert(data.message);
						return false;
					}
				}
			});
		}
	});

	function reload(url) {
		location.href = url;
	}


	function timeCount(seconds){
		verifyTag = false;
		if(seconds == undefined || seconds == null){
			seconds=300;
		}
		setTimeout(function(){
			if(seconds>0){
				seconds--;
				$('.send').text('已发送（'+seconds+'s）').addClass('disabled');
				timeCount(seconds);
			}else{
				$('.send').text('获取验证码').removeClass('disabled');
				verifyTag = true;
			}
		},1000)
	}

</script>
</body>
</html>
